8 * Class for viewing MediaWiki article and history.
10 * This maintains WikiPage functions for backwards compatibility.
12 * @TODO: move and rewrite code to an Action class
14 * See design.txt for an overview.
15 * Note: edit user interface and cache support functions have been
16 * moved to separate EditPage and HTMLFileCache classes.
18 * @internal documentation reviewed 15 Mar 2010
20 class Article
extends Page
{
36 * @var ParserOptions: ParserOptions object for $wgUser articles
38 public $mParserOptions;
40 var $mContent; // !< #BC cruft
48 var $mContentLoaded = false; // !<
54 var $mRedirectedFrom = null;
57 * @var mixed: boolean false or URL string
59 var $mRedirectUrl = false; // !<
60 var $mRevIdFetched = 0; // !<
65 var $mRevision = null;
75 * Constructor and clear the article
76 * @param $title Title Reference to a Title object.
77 * @param $oldId Integer revision ID, null to fetch from request, zero for current
79 public function __construct( Title
$title, $oldId = null ) {
80 $this->mOldId
= $oldId;
81 $this->mPage
= $this->newPage( $title );
88 protected function newPage( Title
$title ) {
89 return new WikiPage( $title );
93 * Constructor from a page id
94 * @param $id Int article ID to load
95 * @return Article|null
97 public static function newFromID( $id ) {
98 $t = Title
::newFromID( $id );
99 # @todo FIXME: Doesn't inherit right
100 return $t == null ?
null : new self( $t );
101 # return $t == null ? null : new static( $t ); // PHP 5.3
105 * Create an Article object of the appropriate class for the given page.
107 * @param $title Title
108 * @param $context IContextSource
109 * @return Article object
111 public static function newFromTitle( $title, IContextSource
$context ) {
112 if ( NS_MEDIA
== $title->getNamespace() ) {
113 // FIXME: where should this go?
114 $title = Title
::makeTitle( NS_FILE
, $title->getDBkey() );
118 wfRunHooks( 'ArticleFromTitle', array( &$title, &$page ) );
120 switch( $title->getNamespace() ) {
122 $page = new ImagePage( $title );
125 $page = new CategoryPage( $title );
128 $page = new Article( $title );
131 $page->setContext( $context );
137 * Create an Article object of the appropriate class for the given page.
139 * @param $page WikiPage
140 * @param $context IContextSource
141 * @return Article object
143 public static function newFromWikiPage( WikiPage
$page, IContextSource
$context ) {
144 $article = self
::newFromTitle( $page->getTitle(), $context );
145 $article->mPage
= $page; // override to keep process cached vars
150 * Tell the page view functions that this view was redirected
151 * from another page on the wiki.
152 * @param $from Title object.
154 public function setRedirectedFrom( Title
$from ) {
155 $this->mRedirectedFrom
= $from;
159 * Get the title object of the article
161 * @return Title object of this page
163 public function getTitle() {
164 return $this->mPage
->getTitle();
168 * Get the WikiPage object of this instance
173 public function getPage() {
180 public function clear() {
181 $this->mContentLoaded
= false;
183 $this->mRedirectedFrom
= null; # Title object if set
184 $this->mRevIdFetched
= 0;
185 $this->mRedirectUrl
= false;
187 $this->mPage
->clear();
191 * Note that getContent/loadContent do not follow redirects anymore.
192 * If you need to fetch redirectable content easily, try
193 * the shortcut in WikiPage::getRedirectTarget()
195 * This function has side effects! Do not use this function if you
196 * only want the real revision text if any.
198 * @deprecated in 1.WD; use getContentObject() instead
200 * @return string Return the text of this revision
202 public function getContent() {
203 wfDeprecated( __METHOD__
, '1.WD' );
204 $content = $this->getContentObject();
205 return ContentHandler
::getContentText( $content );
209 * Returns a Content object representing the pages effective display content,
210 * not necessarily the revision's content!
212 * Note that getContent/loadContent do not follow redirects anymore.
213 * If you need to fetch redirectable content easily, try
214 * the shortcut in WikiPage::getRedirectTarget()
216 * This function has side effects! Do not use this function if you
217 * only want the real revision text if any.
219 * @return Content Return the content of this revision
223 protected function getContentObject() {
225 wfProfileIn( __METHOD__
);
227 if ( $this->mPage
->getID() === 0 ) {
228 # If this is a MediaWiki:x message, then load the messages
229 # and return the message value for x.
230 if ( $this->getTitle()->getNamespace() == NS_MEDIAWIKI
) {
231 $text = $this->getTitle()->getDefaultMessageText();
232 if ( $text === false ) {
236 $content = ContentHandler
::makeContent( $text, $this->getTitle() );
238 $content = new MessageContent( $wgUser->isLoggedIn() ?
'noarticletext' : 'noarticletextanon', null, 'parsemag' );
240 wfProfileOut( __METHOD__
);
244 $this->fetchContentObject();
245 wfProfileOut( __METHOD__
);
247 return $this->mContentObject
;
252 * @return int The oldid of the article that is to be shown, 0 for the
255 public function getOldID() {
256 if ( is_null( $this->mOldId
) ) {
257 $this->mOldId
= $this->getOldIDFromRequest();
260 return $this->mOldId
;
264 * Sets $this->mRedirectUrl to a correct URL if the query parameters are incorrect
266 * @return int The old id for the request
268 public function getOldIDFromRequest() {
269 $this->mRedirectUrl
= false;
271 $request = $this->getContext()->getRequest();
272 $oldid = $request->getIntOrNull( 'oldid' );
274 if ( $oldid === null ) {
278 if ( $oldid !== 0 ) {
279 # Load the given revision and check whether the page is another one.
280 # In that case, update this instance to reflect the change.
281 if ( $oldid === $this->mPage
->getLatest() ) {
282 $this->mRevision
= $this->mPage
->getRevision();
284 $this->mRevision
= Revision
::newFromId( $oldid );
285 if ( $this->mRevision
!== null ) {
286 // Revision title doesn't match the page title given?
287 if ( $this->mPage
->getID() != $this->mRevision
->getPage() ) {
288 $function = array( get_class( $this->mPage
), 'newFromID' );
289 $this->mPage
= call_user_func( $function, $this->mRevision
->getPage() );
295 if ( $request->getVal( 'direction' ) == 'next' ) {
296 $nextid = $this->getTitle()->getNextRevisionID( $oldid );
299 $this->mRevision
= null;
301 $this->mRedirectUrl
= $this->getTitle()->getFullURL( 'redirect=no' );
303 } elseif ( $request->getVal( 'direction' ) == 'prev' ) {
304 $previd = $this->getTitle()->getPreviousRevisionID( $oldid );
307 $this->mRevision
= null;
315 * Load the revision (including text) into this object
317 * @deprecated in 1.19; use fetchContent()
319 function loadContent() {
320 wfDeprecated( __METHOD__
, '1.19' );
321 $this->fetchContent();
325 * Get text of an article from database
326 * Does *NOT* follow redirects.
328 * @return mixed string containing article contents, or false if null
329 * @deprecated in 1.WD, use getContentObject() instead
331 protected function fetchContent() { #BC cruft!
332 wfDeprecated( __METHOD__
, '1.WD' );
334 if ( $this->mContentLoaded
&& $this->mContent
) {
335 return $this->mContent
;
338 wfProfileIn( __METHOD__
);
340 $content = $this->fetchContentObject();
342 $this->mContent
= ContentHandler
::getContentText( $content ); #@todo: get rid of mContent everywhere!
343 wfRunHooks( 'ArticleAfterFetchContent', array( &$this, &$this->mContent
) ); #BC cruft! #XXX: can we deprecate that hook?
345 wfProfileOut( __METHOD__
);
347 return $this->mContent
;
352 * Get text content object
353 * Does *NOT* follow redirects.
354 * TODO: when is this null?
356 * @return Content|null
360 protected function fetchContentObject() {
361 if ( $this->mContentLoaded
) {
362 return $this->mContentObject
;
365 wfProfileIn( __METHOD__
);
367 $this->mContentLoaded
= true;
368 $this->mContent
= null;
370 $oldid = $this->getOldID();
372 # Pre-fill content with error message so that if something
373 # fails we'll have something telling us what we intended.
374 $t = $this->getTitle()->getPrefixedText();
375 $d = $oldid ?
wfMsgExt( 'missingarticle-rev', array( 'escape' ), $oldid ) : '';
376 $this->mContentObject
= new MessageContent( 'missing-article', array($t, $d), array() ) ; // @todo: this isn't page content but a UI message. horrible.
379 # $this->mRevision might already be fetched by getOldIDFromRequest()
380 if ( !$this->mRevision
) {
381 $this->mRevision
= Revision
::newFromId( $oldid );
382 if ( !$this->mRevision
) {
383 wfDebug( __METHOD__
. " failed to retrieve specified revision, id $oldid\n" );
384 wfProfileOut( __METHOD__
);
389 if ( !$this->mPage
->getLatest() ) {
390 wfDebug( __METHOD__
. " failed to find page data for title " . $this->getTitle()->getPrefixedText() . "\n" );
391 wfProfileOut( __METHOD__
);
395 $this->mRevision
= $this->mPage
->getRevision();
397 if ( !$this->mRevision
) {
398 wfDebug( __METHOD__
. " failed to retrieve current page, rev_id " . $this->mPage
->getLatest() . "\n" );
399 wfProfileOut( __METHOD__
);
404 // @todo FIXME: Horrible, horrible! This content-loading interface just plain sucks.
405 // We should instead work with the Revision object when we need it...
406 $this->mContentObject
= $this->mRevision
->getContent( Revision
::FOR_THIS_USER
); // Loads if user is allowed
407 $this->mRevIdFetched
= $this->mRevision
->getId();
409 wfRunHooks( 'ArticleAfterFetchContentObject', array( &$this, &$this->mContentObject
) );
411 wfProfileOut( __METHOD__
);
413 return $this->mContentObject
;
418 * @deprecated since 1.18
420 public function forUpdate() {
421 wfDeprecated( __METHOD__
, '1.18' );
425 * Returns true if the currently-referenced revision is the current edit
426 * to this page (and it exists).
429 public function isCurrent() {
430 # If no oldid, this is the current version.
431 if ( $this->getOldID() == 0 ) {
435 return $this->mPage
->exists() && $this->mRevision
&& $this->mRevision
->isCurrent();
439 * Get the fetched Revision object depending on request parameters or null
443 * @return Revision|null
445 public function getRevisionFetched() {
446 $this->fetchContentObject();
448 return $this->mRevision
;
452 * Use this to fetch the rev ID used on page views
454 * @return int revision ID of last article revision
456 public function getRevIdFetched() {
457 if ( $this->mRevIdFetched
) {
458 return $this->mRevIdFetched
;
460 return $this->mPage
->getLatest();
465 * This is the default action of the index.php entry point: just view the
466 * page of the given title.
468 public function view() {
469 global $wgParser, $wgUseFileCache, $wgUseETag, $wgDebugToolbar;
471 wfProfileIn( __METHOD__
);
473 # Get variables from query string
474 # As side effect this will load the revision and update the title
475 # in a revision ID is passed in the request, so this should remain
476 # the first call of this method even if $oldid is used way below.
477 $oldid = $this->getOldID();
479 $user = $this->getContext()->getUser();
480 # Another whitelist check in case getOldID() is altering the title
481 $permErrors = $this->getTitle()->getUserPermissionsErrors( 'read', $user );
482 if ( count( $permErrors ) ) {
483 wfDebug( __METHOD__
. ": denied on secondary read check\n" );
484 wfProfileOut( __METHOD__
);
485 throw new PermissionsError( 'read', $permErrors );
488 $outputPage = $this->getContext()->getOutput();
489 # getOldID() may as well want us to redirect somewhere else
490 if ( $this->mRedirectUrl
) {
491 $outputPage->redirect( $this->mRedirectUrl
);
492 wfDebug( __METHOD__
. ": redirecting due to oldid\n" );
493 wfProfileOut( __METHOD__
);
498 # If we got diff in the query, we want to see a diff page instead of the article.
499 if ( $this->getContext()->getRequest()->getCheck( 'diff' ) ) {
500 wfDebug( __METHOD__
. ": showing diff page\n" );
501 $this->showDiffPage();
502 wfProfileOut( __METHOD__
);
507 # Set page title (may be overridden by DISPLAYTITLE)
508 $outputPage->setPageTitle( $this->getTitle()->getPrefixedText() );
510 $outputPage->setArticleFlag( true );
511 # Allow frames by default
512 $outputPage->allowClickjacking();
514 $parserCache = ParserCache
::singleton();
516 $parserOptions = $this->getParserOptions();
517 # Render printable version, use printable version cache
518 if ( $outputPage->isPrintable() ) {
519 $parserOptions->setIsPrintable( true );
520 $parserOptions->setEditSection( false );
521 } elseif ( !$this->isCurrent() ||
!$this->getTitle()->quickUserCan( 'edit' ) ) {
522 $parserOptions->setEditSection( false );
525 # Try client and file cache
526 if ( !$wgDebugToolbar && $oldid === 0 && $this->mPage
->checkTouched() ) {
528 $outputPage->setETag( $parserCache->getETag( $this, $parserOptions ) );
531 # Is it client cached?
532 if ( $outputPage->checkLastModified( $this->mPage
->getTouched() ) ) {
533 wfDebug( __METHOD__
. ": done 304\n" );
534 wfProfileOut( __METHOD__
);
538 } elseif ( $wgUseFileCache && $this->tryFileCache() ) {
539 wfDebug( __METHOD__
. ": done file cache\n" );
540 # tell wgOut that output is taken care of
541 $outputPage->disable();
542 $this->mPage
->doViewUpdates( $user );
543 wfProfileOut( __METHOD__
);
549 # Should the parser cache be used?
550 $useParserCache = $this->mPage
->isParserCacheUsed( $parserOptions, $oldid );
551 wfDebug( 'Article::view using parser cache: ' . ( $useParserCache ?
'yes' : 'no' ) . "\n" );
552 if ( $user->getStubThreshold() ) {
553 wfIncrStats( 'pcache_miss_stub' );
556 $this->showRedirectedFromHeader();
557 $this->showNamespaceHeader();
559 # Iterate through the possible ways of constructing the output text.
560 # Keep going until $outputDone is set, or we run out of things to do.
563 $this->mParserOutput
= false;
565 while ( !$outputDone && ++
$pass ) {
568 wfRunHooks( 'ArticleViewHeader', array( &$this, &$outputDone, &$useParserCache ) );
571 # Early abort if the page doesn't exist
572 if ( !$this->mPage
->exists() ) {
573 wfDebug( __METHOD__
. ": showing missing article\n" );
574 $this->showMissingArticle();
575 wfProfileOut( __METHOD__
);
579 # Try the parser cache
580 if ( $useParserCache ) {
581 $this->mParserOutput
= $parserCache->get( $this, $parserOptions );
583 if ( $this->mParserOutput
!== false ) {
585 wfDebug( __METHOD__
. ": showing parser cache contents for current rev permalink\n" );
586 $this->setOldSubtitle( $oldid );
588 wfDebug( __METHOD__
. ": showing parser cache contents\n" );
590 $outputPage->addParserOutput( $this->mParserOutput
);
591 # Ensure that UI elements requiring revision ID have
592 # the correct version information.
593 $outputPage->setRevisionId( $this->mPage
->getLatest() );
594 # Preload timestamp to avoid a DB hit
595 $cachedTimestamp = $this->mParserOutput
->getTimestamp();
596 if ( $cachedTimestamp !== null ) {
597 $outputPage->setRevisionTimestamp( $cachedTimestamp );
598 $this->mPage
->setTimestamp( $cachedTimestamp );
605 # This will set $this->mRevision if needed
606 $this->fetchContentObject();
608 # Are we looking at an old revision
609 if ( $oldid && $this->mRevision
) {
610 $this->setOldSubtitle( $oldid );
612 if ( !$this->showDeletedRevisionHeader() ) {
613 wfDebug( __METHOD__
. ": cannot view deleted revision\n" );
614 wfProfileOut( __METHOD__
);
619 # Ensure that UI elements requiring revision ID have
620 # the correct version information.
621 $outputPage->setRevisionId( $this->getRevIdFetched() );
622 # Preload timestamp to avoid a DB hit
623 $outputPage->setRevisionTimestamp( $this->getTimestamp() );
625 # Pages containing custom CSS or JavaScript get special treatment
626 if ( $this->getTitle()->isCssOrJsPage() ||
$this->getTitle()->isCssJsSubpage() ) {
627 wfDebug( __METHOD__
. ": showing CSS/JS source\n" );
628 $this->showCssOrJsPage();
630 } elseif( !wfRunHooks( 'ArticleContentViewCustom', array( $this->fetchContentObject(), $this->getTitle(), $outputPage ) ) ) {
631 # Allow extensions do their own custom view for certain pages
633 } elseif( Hooks
::isRegistered( 'ArticleViewCustom' ) && !wfRunHooks( 'ArticleViewCustom', array( $this->fetchContent(), $this->getTitle(), $outputPage ) ) ) { #FIXME: fetchContent() is deprecated!
634 # Allow extensions do their own custom view for certain pages
637 $content = $this->getContentObject();
638 $rt = $content->getRedirectChain();
640 wfDebug( __METHOD__
. ": showing redirect=no page\n" );
641 # Viewing a redirect page (e.g. with parameter redirect=no)
642 $outputPage->addHTML( $this->viewRedirect( $rt ) );
643 # Parse just to get categories, displaytitle, etc.
644 $this->mParserOutput
= $content->getParserOutput( $this->getTitle(), $oldid, $parserOptions, false );
645 $outputPage->addParserOutputNoText( $this->mParserOutput
);
651 # Run the parse, protected by a pool counter
652 wfDebug( __METHOD__
. ": doing uncached parse\n" );
654 // @todo: shouldn't we be passing $this->getPage() to PoolWorkArticleView instead of plain $this?
655 $poolArticleView = new PoolWorkArticleView( $this, $parserOptions,
656 $this->getRevIdFetched(), $useParserCache, $this->getContentObject(), $this->getContext() );
658 if ( !$poolArticleView->execute() ) {
659 $error = $poolArticleView->getError();
661 $outputPage->clearHTML(); // for release() errors
662 $outputPage->enableClientCache( false );
663 $outputPage->setRobotPolicy( 'noindex,nofollow' );
665 $errortext = $error->getWikiText( false, 'view-pool-error' );
666 $outputPage->addWikiText( '<div class="errorbox">' . $errortext . '</div>' );
668 # Connection or timeout error
669 wfProfileOut( __METHOD__
);
673 $this->mParserOutput
= $poolArticleView->getParserOutput();
674 $outputPage->addParserOutput( $this->mParserOutput
);
676 # Don't cache a dirty ParserOutput object
677 if ( $poolArticleView->getIsDirty() ) {
678 $outputPage->setSquidMaxage( 0 );
679 $outputPage->addHTML( "<!-- parser cache is expired, sending anyway due to pool overload-->\n" );
684 # Should be unreachable, but just in case...
690 # Get the ParserOutput actually *displayed* here.
691 # Note that $this->mParserOutput is the *current* version output.
692 $pOutput = ( $outputDone instanceof ParserOutput
)
693 ?
$outputDone // object fetched by hook
694 : $this->mParserOutput
;
696 # Adjust title for main page & pages with displaytitle
698 $this->adjustDisplayTitle( $pOutput );
701 # For the main page, overwrite the <title> element with the con-
702 # tents of 'pagetitle-view-mainpage' instead of the default (if
704 # This message always exists because it is in the i18n files
705 if ( $this->getTitle()->isMainPage() ) {
706 $msg = wfMessage( 'pagetitle-view-mainpage' )->inContentLanguage();
707 if ( !$msg->isDisabled() ) {
708 $outputPage->setHTMLTitle( $msg->title( $this->getTitle() )->text() );
712 # Check for any __NOINDEX__ tags on the page using $pOutput
713 $policy = $this->getRobotPolicy( 'view', $pOutput );
714 $outputPage->setIndexPolicy( $policy['index'] );
715 $outputPage->setFollowPolicy( $policy['follow'] );
717 $this->showViewFooter();
718 $this->mPage
->doViewUpdates( $user );
720 wfProfileOut( __METHOD__
);
724 * Adjust title for pages with displaytitle, -{T|}- or language conversion
725 * @param $pOutput ParserOutput
727 public function adjustDisplayTitle( ParserOutput
$pOutput ) {
728 # Adjust the title if it was set by displaytitle, -{T|}- or language conversion
729 $titleText = $pOutput->getTitleText();
730 if ( strval( $titleText ) !== '' ) {
731 $this->getContext()->getOutput()->setPageTitle( $titleText );
736 * Show a diff page according to current request variables. For use within
737 * Article::view() only, other callers should use the DifferenceEngine class.
739 public function showDiffPage() {
740 $request = $this->getContext()->getRequest();
741 $user = $this->getContext()->getUser();
742 $diff = $request->getVal( 'diff' );
743 $rcid = $request->getVal( 'rcid' );
744 $diffOnly = $request->getBool( 'diffonly', $user->getOption( 'diffonly' ) );
745 $purge = $request->getVal( 'action' ) == 'purge';
746 $unhide = $request->getInt( 'unhide' ) == 1;
747 $oldid = $this->getOldID();
749 $contentHandler = ContentHandler
::getForTitle( $this->getTitle() );
750 $de = $contentHandler->createDifferenceEngine( $this->getContext(), $oldid, $diff, $rcid, $purge, $unhide );
752 // DifferenceEngine directly fetched the revision:
753 $this->mRevIdFetched
= $de->mNewid
;
754 $de->showDiffPage( $diffOnly );
756 if ( $diff == 0 ||
$diff == $this->mPage
->getLatest() ) {
757 # Run view updates for current revision only
758 $this->mPage
->doViewUpdates( $user );
763 * Show a page view for a page formatted as CSS or JavaScript. To be called by
764 * Article::view() only.
766 * This is hooked by SyntaxHighlight_GeSHi to do syntax highlighting of these
769 protected function showCssOrJsPage( $showCacheHint = true ) {
772 if ( $showCacheHint ) {
773 $dir = $this->getContext()->getLanguage()->getDir();
774 $lang = $this->getContext()->getLanguage()->getCode();
776 $wgOut->wrapWikiMsg( "<div id='mw-clearyourcache' lang='$lang' dir='$dir' class='mw-content-$dir'>\n$1\n</div>",
780 // Give hooks a chance to customise the output
781 if ( !Hooks
::isRegistered('ShowRawCssJs') ||
wfRunHooks( 'ShowRawCssJs', array( $this->fetchContent(), $this->getTitle(), $wgOut ) ) ) { #FIXME: fetchContent() is deprecated
782 $po = $this->mContentObject
->getParserOutput( $this->getTitle() );
783 $wgOut->addHTML( $po->getText() );
788 * Get the robot policy to be used for the current view
789 * @param $action String the action= GET parameter
790 * @param $pOutput ParserOutput
791 * @return Array the policy that should be set
792 * TODO: actions other than 'view'
794 public function getRobotPolicy( $action, $pOutput ) {
795 global $wgArticleRobotPolicies, $wgNamespaceRobotPolicies, $wgDefaultRobotPolicy;
797 $ns = $this->getTitle()->getNamespace();
799 if ( $ns == NS_USER ||
$ns == NS_USER_TALK
) {
800 # Don't index user and user talk pages for blocked users (bug 11443)
801 if ( !$this->getTitle()->isSubpage() ) {
802 if ( Block
::newFromTarget( null, $this->getTitle()->getText() ) instanceof Block
) {
804 'index' => 'noindex',
805 'follow' => 'nofollow'
811 if ( $this->mPage
->getID() === 0 ||
$this->getOldID() ) {
812 # Non-articles (special pages etc), and old revisions
814 'index' => 'noindex',
815 'follow' => 'nofollow'
817 } elseif ( $this->getContext()->getOutput()->isPrintable() ) {
818 # Discourage indexing of printable versions, but encourage following
820 'index' => 'noindex',
823 } elseif ( $this->getContext()->getRequest()->getInt( 'curid' ) ) {
824 # For ?curid=x urls, disallow indexing
826 'index' => 'noindex',
831 # Otherwise, construct the policy based on the various config variables.
832 $policy = self
::formatRobotPolicy( $wgDefaultRobotPolicy );
834 if ( isset( $wgNamespaceRobotPolicies[$ns] ) ) {
835 # Honour customised robot policies for this namespace
836 $policy = array_merge(
838 self
::formatRobotPolicy( $wgNamespaceRobotPolicies[$ns] )
841 if ( $this->getTitle()->canUseNoindex() && is_object( $pOutput ) && $pOutput->getIndexPolicy() ) {
842 # __INDEX__ and __NOINDEX__ magic words, if allowed. Incorporates
843 # a final sanity check that we have really got the parser output.
844 $policy = array_merge(
846 array( 'index' => $pOutput->getIndexPolicy() )
850 if ( isset( $wgArticleRobotPolicies[$this->getTitle()->getPrefixedText()] ) ) {
851 # (bug 14900) site config can override user-defined __INDEX__ or __NOINDEX__
852 $policy = array_merge(
854 self
::formatRobotPolicy( $wgArticleRobotPolicies[$this->getTitle()->getPrefixedText()] )
862 * Converts a String robot policy into an associative array, to allow
863 * merging of several policies using array_merge().
864 * @param $policy Mixed, returns empty array on null/false/'', transparent
865 * to already-converted arrays, converts String.
866 * @return Array: 'index' => <indexpolicy>, 'follow' => <followpolicy>
868 public static function formatRobotPolicy( $policy ) {
869 if ( is_array( $policy ) ) {
871 } elseif ( !$policy ) {
875 $policy = explode( ',', $policy );
876 $policy = array_map( 'trim', $policy );
879 foreach ( $policy as $var ) {
880 if ( in_array( $var, array( 'index', 'noindex' ) ) ) {
881 $arr['index'] = $var;
882 } elseif ( in_array( $var, array( 'follow', 'nofollow' ) ) ) {
883 $arr['follow'] = $var;
891 * If this request is a redirect view, send "redirected from" subtitle to
892 * the output. Returns true if the header was needed, false if this is not
893 * a redirect view. Handles both local and remote redirects.
897 public function showRedirectedFromHeader() {
898 global $wgRedirectSources;
899 $outputPage = $this->getContext()->getOutput();
901 $rdfrom = $this->getContext()->getRequest()->getVal( 'rdfrom' );
903 if ( isset( $this->mRedirectedFrom
) ) {
904 // This is an internally redirected page view.
905 // We'll need a backlink to the source page for navigation.
906 if ( wfRunHooks( 'ArticleViewRedirect', array( &$this ) ) ) {
907 $redir = Linker
::linkKnown(
908 $this->mRedirectedFrom
,
911 array( 'redirect' => 'no' )
914 $outputPage->addSubtitle( wfMessage( 'redirectedfrom' )->rawParams( $redir ) );
916 // Set the fragment if one was specified in the redirect
917 if ( strval( $this->getTitle()->getFragment() ) != '' ) {
918 $fragment = Xml
::escapeJsString( $this->getTitle()->getFragmentForURL() );
919 $outputPage->addInlineScript( "redirectToFragment(\"$fragment\");" );
922 // Add a <link rel="canonical"> tag
923 $outputPage->addLink( array( 'rel' => 'canonical',
924 'href' => $this->getTitle()->getLocalURL() )
927 // Tell the output object that the user arrived at this article through a redirect
928 $outputPage->setRedirectedFrom( $this->mRedirectedFrom
);
932 } elseif ( $rdfrom ) {
933 // This is an externally redirected view, from some other wiki.
934 // If it was reported from a trusted site, supply a backlink.
935 if ( $wgRedirectSources && preg_match( $wgRedirectSources, $rdfrom ) ) {
936 $redir = Linker
::makeExternalLink( $rdfrom, $rdfrom );
937 $outputPage->addSubtitle( wfMessage( 'redirectedfrom' )->rawParams( $redir ) );
947 * Show a header specific to the namespace currently being viewed, like
948 * [[MediaWiki:Talkpagetext]]. For Article::view().
950 public function showNamespaceHeader() {
951 if ( $this->getTitle()->isTalkPage() ) {
952 if ( !wfMessage( 'talkpageheader' )->isDisabled() ) {
953 $this->getContext()->getOutput()->wrapWikiMsg( "<div class=\"mw-talkpageheader\">\n$1\n</div>", array( 'talkpageheader' ) );
959 * Show the footer section of an ordinary page view
961 public function showViewFooter() {
962 # check if we're displaying a [[User talk:x.x.x.x]] anonymous talk page
963 if ( $this->getTitle()->getNamespace() == NS_USER_TALK
&& IP
::isValid( $this->getTitle()->getText() ) ) {
964 $this->getContext()->getOutput()->addWikiMsg( 'anontalkpagetext' );
967 # If we have been passed an &rcid= parameter, we want to give the user a
968 # chance to mark this new article as patrolled.
969 $this->showPatrolFooter();
971 wfRunHooks( 'ArticleViewFooter', array( $this ) );
976 * If patrol is possible, output a patrol UI box. This is called from the
977 * footer section of ordinary page views. If patrol is not possible or not
978 * desired, does nothing.
980 public function showPatrolFooter() {
981 $request = $this->getContext()->getRequest();
982 $outputPage = $this->getContext()->getOutput();
983 $user = $this->getContext()->getUser();
984 $rcid = $request->getVal( 'rcid' );
986 if ( !$rcid ||
!$this->getTitle()->quickUserCan( 'patrol' ) ) {
990 $token = $user->getEditToken( $rcid );
991 $outputPage->preventClickjacking();
993 $outputPage->addHTML(
994 "<div class='patrollink'>" .
996 'markaspatrolledlink',
999 wfMsgHtml( 'markaspatrolledtext' ),
1002 'action' => 'markpatrolled',
1006 array( 'known', 'noclasses' )
1014 * Show the error text for a missing article. For articles in the MediaWiki
1015 * namespace, show the default message text. To be called from Article::view().
1017 public function showMissingArticle() {
1018 global $wgSend404Code;
1019 $outputPage = $this->getContext()->getOutput();
1021 # Show info in user (talk) namespace. Does the user exist? Is he blocked?
1022 if ( $this->getTitle()->getNamespace() == NS_USER ||
$this->getTitle()->getNamespace() == NS_USER_TALK
) {
1023 $parts = explode( '/', $this->getTitle()->getText() );
1024 $rootPart = $parts[0];
1025 $user = User
::newFromName( $rootPart, false /* allow IP users*/ );
1026 $ip = User
::isIP( $rootPart );
1028 if ( !($user && $user->isLoggedIn()) && !$ip ) { # User does not exist
1029 $outputPage->wrapWikiMsg( "<div class=\"mw-userpage-userdoesnotexist error\">\n\$1\n</div>",
1030 array( 'userpage-userdoesnotexist-view', wfEscapeWikiText( $rootPart ) ) );
1031 } elseif ( $user->isBlocked() ) { # Show log extract if the user is currently blocked
1032 LogEventsList
::showLogExtract(
1035 $user->getUserPage()->getPrefixedText(),
1039 'showIfEmpty' => false,
1041 'blocked-notice-logextract',
1042 $user->getName() # Support GENDER in notice
1049 wfRunHooks( 'ShowMissingArticle', array( $this ) );
1051 # Show delete and move logs
1052 LogEventsList
::showLogExtract( $outputPage, array( 'delete', 'move' ), $this->getTitle()->getPrefixedText(), '',
1054 'conds' => array( "log_action != 'revision'" ),
1055 'showIfEmpty' => false,
1056 'msgKey' => array( 'moveddeleted-notice' ) )
1059 if ( !$this->mPage
->hasViewableContent() && $wgSend404Code ) {
1060 // If there's no backing content, send a 404 Not Found
1061 // for better machine handling of broken links.
1062 $this->getContext()->getRequest()->response()->header( "HTTP/1.1 404 Not Found" );
1065 $hookResult = wfRunHooks( 'BeforeDisplayNoArticleText', array( $this ) );
1067 if ( ! $hookResult ) {
1071 # Show error message
1072 $oldid = $this->getOldID();
1074 $text = wfMsgNoTrans( 'missing-article',
1075 $this->getTitle()->getPrefixedText(),
1076 wfMsgNoTrans( 'missingarticle-rev', $oldid ) );
1077 } elseif ( $this->getTitle()->getNamespace() === NS_MEDIAWIKI
) {
1078 // Use the default message text
1079 $text = $this->getTitle()->getDefaultMessageText();
1081 $createErrors = $this->getTitle()->getUserPermissionsErrors( 'create', $this->getContext()->getUser() );
1082 $editErrors = $this->getTitle()->getUserPermissionsErrors( 'edit', $this->getContext()->getUser() );
1083 $errors = array_merge( $createErrors, $editErrors );
1085 if ( !count( $errors ) ) {
1086 $text = wfMsgNoTrans( 'noarticletext' );
1088 $text = wfMsgNoTrans( 'noarticletext-nopermission' );
1091 $text = "<div class='noarticletext'>\n$text\n</div>";
1093 $outputPage->addWikiText( $text );
1097 * If the revision requested for view is deleted, check permissions.
1098 * Send either an error message or a warning header to the output.
1100 * @return boolean true if the view is allowed, false if not.
1102 public function showDeletedRevisionHeader() {
1103 if ( !$this->mRevision
->isDeleted( Revision
::DELETED_TEXT
) ) {
1108 $outputPage = $this->getContext()->getOutput();
1109 // If the user is not allowed to see it...
1110 if ( !$this->mRevision
->userCan( Revision
::DELETED_TEXT
) ) {
1111 $outputPage->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n",
1112 'rev-deleted-text-permission' );
1115 // If the user needs to confirm that they want to see it...
1116 } elseif ( $this->getContext()->getRequest()->getInt( 'unhide' ) != 1 ) {
1117 # Give explanation and add a link to view the revision...
1118 $oldid = intval( $this->getOldID() );
1119 $link = $this->getTitle()->getFullUrl( "oldid={$oldid}&unhide=1" );
1120 $msg = $this->mRevision
->isDeleted( Revision
::DELETED_RESTRICTED
) ?
1121 'rev-suppressed-text-unhide' : 'rev-deleted-text-unhide';
1122 $outputPage->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n",
1123 array( $msg, $link ) );
1126 // We are allowed to see...
1128 $msg = $this->mRevision
->isDeleted( Revision
::DELETED_RESTRICTED
) ?
1129 'rev-suppressed-text-view' : 'rev-deleted-text-view';
1130 $outputPage->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n", $msg );
1137 * Generate the navigation links when browsing through an article revisions
1138 * It shows the information as:
1139 * Revision as of \<date\>; view current revision
1140 * \<- Previous version | Next Version -\>
1142 * @param $oldid int: revision ID of this article revision
1144 public function setOldSubtitle( $oldid = 0 ) {
1145 if ( !wfRunHooks( 'DisplayOldSubtitle', array( &$this, &$oldid ) ) ) {
1149 $unhide = $this->getContext()->getRequest()->getInt( 'unhide' ) == 1;
1151 # Cascade unhide param in links for easy deletion browsing
1152 $extraParams = array();
1154 $extraParams['unhide'] = 1;
1157 if ( $this->mRevision
&& $this->mRevision
->getId() === $oldid ) {
1158 $revision = $this->mRevision
;
1160 $revision = Revision
::newFromId( $oldid );
1163 $timestamp = $revision->getTimestamp();
1165 $current = ( $oldid == $this->mPage
->getLatest() );
1166 $language = $this->getContext()->getLanguage();
1167 $td = $language->timeanddate( $timestamp, true );
1168 $tddate = $language->date( $timestamp, true );
1169 $tdtime = $language->time( $timestamp, true );
1171 # Show user links if allowed to see them. If hidden, then show them only if requested...
1172 $userlinks = Linker
::revUserTools( $revision, !$unhide );
1174 $infomsg = $current && !wfMessage( 'revision-info-current' )->isDisabled()
1175 ?
'revision-info-current'
1178 $outputPage = $this->getContext()->getOutput();
1179 $outputPage->addSubtitle( "<div id=\"mw-{$infomsg}\">" . wfMessage( $infomsg,
1180 $td )->rawParams( $userlinks )->params( $revision->getID(), $tddate,
1181 $tdtime, $revision->getUser() )->parse() . "</div>" );
1184 ?
wfMsgHtml( 'currentrevisionlink' )
1187 wfMsgHtml( 'currentrevisionlink' ),
1190 array( 'known', 'noclasses' )
1193 ?
wfMsgHtml( 'diff' )
1196 wfMsgHtml( 'diff' ),
1202 array( 'known', 'noclasses' )
1204 $prev = $this->getTitle()->getPreviousRevisionID( $oldid ) ;
1208 wfMsgHtml( 'previousrevision' ),
1211 'direction' => 'prev',
1214 array( 'known', 'noclasses' )
1216 : wfMsgHtml( 'previousrevision' );
1220 wfMsgHtml( 'diff' ),
1226 array( 'known', 'noclasses' )
1228 : wfMsgHtml( 'diff' );
1229 $nextlink = $current
1230 ?
wfMsgHtml( 'nextrevision' )
1233 wfMsgHtml( 'nextrevision' ),
1236 'direction' => 'next',
1239 array( 'known', 'noclasses' )
1241 $nextdiff = $current
1242 ?
wfMsgHtml( 'diff' )
1245 wfMsgHtml( 'diff' ),
1251 array( 'known', 'noclasses' )
1254 $cdel = Linker
::getRevDeleteLink( $this->getContext()->getUser(), $revision, $this->getTitle() );
1255 if ( $cdel !== '' ) {
1259 $outputPage->addSubtitle( "<div id=\"mw-revision-nav\">" . $cdel .
1260 wfMsgExt( 'revision-nav', array( 'escapenoentities', 'parsemag', 'replaceafter' ),
1261 $prevdiff, $prevlink, $lnk, $curdiff, $nextlink, $nextdiff ) . "</div>" );
1267 * @param $target Title|Array of destination(s) to redirect
1268 * @param $appendSubtitle Boolean [optional]
1269 * @param $forceKnown Boolean: should the image be shown as a bluelink regardless of existence?
1270 * @return string containing HMTL with redirect link
1272 public function viewRedirect( $target, $appendSubtitle = true, $forceKnown = false ) {
1273 global $wgStylePath;
1275 if ( !is_array( $target ) ) {
1276 $target = array( $target );
1279 $lang = $this->getTitle()->getPageLanguage();
1280 $imageDir = $lang->getDir();
1282 if ( $appendSubtitle ) {
1283 $this->getContext()->getOutput()->appendSubtitle( wfMsgHtml( 'redirectpagesub' ) );
1286 // the loop prepends the arrow image before the link, so the first case needs to be outside
1291 $title = array_shift( $target );
1293 if ( $forceKnown ) {
1294 $link = Linker
::linkKnown( $title, htmlspecialchars( $title->getFullText() ) );
1296 $link = Linker
::link( $title, htmlspecialchars( $title->getFullText() ) );
1299 $nextRedirect = $wgStylePath . '/common/images/nextredirect' . $imageDir . '.png';
1300 $alt = $lang->isRTL() ?
'←' : '→';
1301 // Automatically append redirect=no to each link, since most of them are redirect pages themselves.
1302 foreach ( $target as $rt ) {
1303 $link .= Html
::element( 'img', array( 'src' => $nextRedirect, 'alt' => $alt ) );
1304 if ( $forceKnown ) {
1305 $link .= Linker
::linkKnown( $rt, htmlspecialchars( $rt->getFullText(), array(), array( 'redirect' => 'no' ) ) );
1307 $link .= Linker
::link( $rt, htmlspecialchars( $rt->getFullText() ), array(), array( 'redirect' => 'no' ) );
1311 $imageUrl = $wgStylePath . '/common/images/redirect' . $imageDir . '.png';
1312 return '<div class="redirectMsg">' .
1313 Html
::element( 'img', array( 'src' => $imageUrl, 'alt' => '#REDIRECT' ) ) .
1314 '<span class="redirectText">' . $link . '</span></div>';
1318 * Handle action=render
1320 public function render() {
1321 $this->getContext()->getOutput()->setArticleBodyOnly( true );
1326 * action=protect handler
1328 public function protect() {
1329 $form = new ProtectionForm( $this );
1334 * action=unprotect handler (alias)
1336 public function unprotect() {
1341 * UI entry point for page deletion
1343 public function delete() {
1344 # This code desperately needs to be totally rewritten
1346 $title = $this->getTitle();
1347 $user = $this->getContext()->getUser();
1350 $permission_errors = $title->getUserPermissionsErrors( 'delete', $user );
1351 if ( count( $permission_errors ) ) {
1352 throw new PermissionsError( 'delete', $permission_errors );
1355 # Read-only check...
1356 if ( wfReadOnly() ) {
1357 throw new ReadOnlyError
;
1360 # Better double-check that it hasn't been deleted yet!
1361 $dbw = wfGetDB( DB_MASTER
);
1362 $conds = $title->pageCond();
1363 $latest = $dbw->selectField( 'page', 'page_latest', $conds, __METHOD__
);
1364 if ( $latest === false ) {
1365 $outputPage = $this->getContext()->getOutput();
1366 $outputPage->setPageTitle( wfMessage( 'cannotdelete-title', $title->getPrefixedText() ) );
1367 $outputPage->wrapWikiMsg( "<div class=\"error mw-error-cannotdelete\">\n$1\n</div>",
1368 array( 'cannotdelete', wfEscapeWikiText( $title->getPrefixedText() ) )
1370 $outputPage->addHTML( Xml
::element( 'h2', null, LogPage
::logName( 'delete' ) ) );
1371 LogEventsList
::showLogExtract(
1374 $title->getPrefixedText()
1380 $request = $this->getContext()->getRequest();
1381 $deleteReasonList = $request->getText( 'wpDeleteReasonList', 'other' );
1382 $deleteReason = $request->getText( 'wpReason' );
1384 if ( $deleteReasonList == 'other' ) {
1385 $reason = $deleteReason;
1386 } elseif ( $deleteReason != '' ) {
1387 // Entry from drop down menu + additional comment
1388 $reason = $deleteReasonList . wfMsgForContent( 'colon-separator' ) . $deleteReason;
1390 $reason = $deleteReasonList;
1393 if ( $request->wasPosted() && $user->matchEditToken( $request->getVal( 'wpEditToken' ),
1394 array( 'delete', $this->getTitle()->getPrefixedText() ) ) )
1396 # Flag to hide all contents of the archived revisions
1397 $suppress = $request->getVal( 'wpSuppress' ) && $user->isAllowed( 'suppressrevision' );
1399 $this->doDelete( $reason, $suppress );
1401 if ( $request->getCheck( 'wpWatch' ) && $user->isLoggedIn() ) {
1403 } elseif ( $title->userIsWatching() ) {
1410 // Generate deletion reason
1411 $hasHistory = false;
1414 $reason = $this->generateReason( $hasHistory );
1415 } catch (MWException
$e) {
1416 # if a page is horribly broken, we still want to be able to delete it. so be lenient about errors here.
1417 wfDebug("Error while building auto delete summary: $e");
1422 // If the page has a history, insert a warning
1423 if ( $hasHistory ) {
1424 $revisions = $this->mTitle
->estimateRevisionCount();
1425 // @todo FIXME: i18n issue/patchwork message
1426 $this->getContext()->getOutput()->addHTML( '<strong class="mw-delete-warning-revisions">' .
1427 wfMsgExt( 'historywarning', array( 'parseinline' ), $this->getContext()->getLanguage()->formatNum( $revisions ) ) .
1428 wfMsgHtml( 'word-separator' ) . Linker
::link( $title,
1429 wfMsgHtml( 'history' ),
1430 array( 'rel' => 'archives' ),
1431 array( 'action' => 'history' ) ) .
1435 if ( $this->mTitle
->isBigDeletion() ) {
1436 global $wgDeleteRevisionsLimit;
1437 $this->getContext()->getOutput()->wrapWikiMsg( "<div class='error'>\n$1\n</div>\n",
1438 array( 'delete-warning-toobig', $this->getContext()->getLanguage()->formatNum( $wgDeleteRevisionsLimit ) ) );
1442 return $this->confirmDelete( $reason );
1446 * Output deletion confirmation dialog
1447 * @todo FIXME: Move to another file?
1448 * @param $reason String: prefilled reason
1450 public function confirmDelete( $reason ) {
1451 wfDebug( "Article::confirmDelete\n" );
1453 $outputPage = $this->getContext()->getOutput();
1454 $outputPage->setPageTitle( wfMessage( 'delete-confirm', $this->getTitle()->getPrefixedText() ) );
1455 $outputPage->addBacklinkSubtitle( $this->getTitle() );
1456 $outputPage->setRobotPolicy( 'noindex,nofollow' );
1457 $outputPage->addWikiMsg( 'confirmdeletetext' );
1459 wfRunHooks( 'ArticleConfirmDelete', array( $this, $outputPage, &$reason ) );
1461 $user = $this->getContext()->getUser();
1463 if ( $user->isAllowed( 'suppressrevision' ) ) {
1464 $suppress = "<tr id=\"wpDeleteSuppressRow\">
1466 <td class='mw-input'><strong>" .
1467 Xml
::checkLabel( wfMsg( 'revdelete-suppress' ),
1468 'wpSuppress', 'wpSuppress', false, array( 'tabindex' => '4' ) ) .
1474 $checkWatch = $user->getBoolOption( 'watchdeletion' ) ||
$this->getTitle()->userIsWatching();
1476 $form = Xml
::openElement( 'form', array( 'method' => 'post',
1477 'action' => $this->getTitle()->getLocalURL( 'action=delete' ), 'id' => 'deleteconfirm' ) ) .
1478 Xml
::openElement( 'fieldset', array( 'id' => 'mw-delete-table' ) ) .
1479 Xml
::tags( 'legend', null, wfMsgExt( 'delete-legend', array( 'parsemag', 'escapenoentities' ) ) ) .
1480 Xml
::openElement( 'table', array( 'id' => 'mw-deleteconfirm-table' ) ) .
1481 "<tr id=\"wpDeleteReasonListRow\">
1482 <td class='mw-label'>" .
1483 Xml
::label( wfMsg( 'deletecomment' ), 'wpDeleteReasonList' ) .
1485 <td class='mw-input'>" .
1486 Xml
::listDropDown( 'wpDeleteReasonList',
1487 wfMsgForContent( 'deletereason-dropdown' ),
1488 wfMsgForContent( 'deletereasonotherlist' ), '', 'wpReasonDropDown', 1 ) .
1491 <tr id=\"wpDeleteReasonRow\">
1492 <td class='mw-label'>" .
1493 Xml
::label( wfMsg( 'deleteotherreason' ), 'wpReason' ) .
1495 <td class='mw-input'>" .
1496 Html
::input( 'wpReason', $reason, 'text', array(
1498 'maxlength' => '255',
1506 # Disallow watching if user is not logged in
1507 if ( $user->isLoggedIn() ) {
1511 <td class='mw-input'>" .
1512 Xml
::checkLabel( wfMsg( 'watchthis' ),
1513 'wpWatch', 'wpWatch', $checkWatch, array( 'tabindex' => '3' ) ) .
1522 <td class='mw-submit'>" .
1523 Xml
::submitButton( wfMsg( 'deletepage' ),
1524 array( 'name' => 'wpConfirmB', 'id' => 'wpConfirmB', 'tabindex' => '5' ) ) .
1527 Xml
::closeElement( 'table' ) .
1528 Xml
::closeElement( 'fieldset' ) .
1529 Html
::hidden( 'wpEditToken', $user->getEditToken( array( 'delete', $this->getTitle()->getPrefixedText() ) ) ) .
1530 Xml
::closeElement( 'form' );
1532 if ( $user->isAllowed( 'editinterface' ) ) {
1533 $title = Title
::makeTitle( NS_MEDIAWIKI
, 'Deletereason-dropdown' );
1534 $link = Linker
::link(
1536 wfMsgHtml( 'delete-edit-reasonlist' ),
1538 array( 'action' => 'edit' )
1540 $form .= '<p class="mw-delete-editreasons">' . $link . '</p>';
1543 $outputPage->addHTML( $form );
1544 $outputPage->addHTML( Xml
::element( 'h2', null, LogPage
::logName( 'delete' ) ) );
1545 LogEventsList
::showLogExtract( $outputPage, 'delete',
1546 $this->getTitle()->getPrefixedText()
1551 * Perform a deletion and output success or failure messages
1553 * @param $suppress bool
1555 public function doDelete( $reason, $suppress = false ) {
1557 $outputPage = $this->getContext()->getOutput();
1558 if ( $this->mPage
->doDeleteArticle( $reason, $suppress, 0, true, $error ) ) {
1559 $deleted = $this->getTitle()->getPrefixedText();
1561 $outputPage->setPageTitle( wfMessage( 'actioncomplete' ) );
1562 $outputPage->setRobotPolicy( 'noindex,nofollow' );
1564 $loglink = '[[Special:Log/delete|' . wfMsgNoTrans( 'deletionlog' ) . ']]';
1566 $outputPage->addWikiMsg( 'deletedtext', wfEscapeWikiText( $deleted ), $loglink );
1567 $outputPage->returnToMain( false );
1569 $outputPage->setPageTitle( wfMessage( 'cannotdelete-title', $this->getTitle()->getPrefixedText() ) );
1570 if ( $error == '' ) {
1571 $outputPage->wrapWikiMsg( "<div class=\"error mw-error-cannotdelete\">\n$1\n</div>",
1572 array( 'cannotdelete', wfEscapeWikiText( $this->getTitle()->getPrefixedText() ) )
1574 $outputPage->addHTML( Xml
::element( 'h2', null, LogPage
::logName( 'delete' ) ) );
1576 LogEventsList
::showLogExtract(
1579 $this->getTitle()->getPrefixedText()
1582 $outputPage->addHTML( $error );
1587 /* Caching functions */
1590 * checkLastModified returns true if it has taken care of all
1591 * output to the client that is necessary for this request.
1592 * (that is, it has sent a cached version of the page)
1594 * @return boolean true if cached version send, false otherwise
1596 protected function tryFileCache() {
1597 static $called = false;
1600 wfDebug( "Article::tryFileCache(): called twice!?\n" );
1605 if ( $this->isFileCacheable() ) {
1606 $cache = HTMLFileCache
::newFromTitle( $this->getTitle(), 'view' );
1607 if ( $cache->isCacheGood( $this->mPage
->getTouched() ) ) {
1608 wfDebug( "Article::tryFileCache(): about to load file\n" );
1609 $cache->loadFromFileCache( $this->getContext() );
1612 wfDebug( "Article::tryFileCache(): starting buffer\n" );
1613 ob_start( array( &$cache, 'saveToFileCache' ) );
1616 wfDebug( "Article::tryFileCache(): not cacheable\n" );
1623 * Check if the page can be cached
1626 public function isFileCacheable() {
1629 if ( HTMLFileCache
::useFileCache( $this->getContext() ) ) {
1630 $cacheable = $this->mPage
->getID()
1631 && !$this->mRedirectedFrom
&& !$this->getTitle()->isRedirect();
1632 // Extension may have reason to disable file caching on some pages.
1634 $cacheable = wfRunHooks( 'IsFileCacheable', array( &$this ) );
1644 * Lightweight method to get the parser output for a page, checking the parser cache
1645 * and so on. Doesn't consider most of the stuff that WikiPage::view is forced to
1646 * consider, so it's not appropriate to use there.
1648 * @since 1.16 (r52326) for LiquidThreads
1650 * @param $oldid mixed integer Revision ID or null
1651 * @param $user User The relevant user
1652 * @return ParserOutput or false if the given revsion ID is not found
1654 public function getParserOutput( $oldid = null, User
$user = null ) {
1655 $user = is_null( $user ) ?
$this->getContext()->getUser() : $user;
1656 $parserOptions = $this->mPage
->makeParserOptions( $user );
1658 return $this->mPage
->getParserOutput( $parserOptions, $oldid );
1662 * Get parser options suitable for rendering the primary article wikitext
1663 * @return ParserOptions
1665 public function getParserOptions() {
1666 if ( !$this->mParserOptions
) {
1667 $this->mParserOptions
= $this->mPage
->makeParserOptions( $this->getContext()->getUser() );
1669 // Clone to allow modifications of the return value without affecting cache
1670 return clone $this->mParserOptions
;
1674 * Sets the context this Article is executed in
1676 * @param $context IContextSource
1679 public function setContext( $context ) {
1680 $this->mContext
= $context;
1684 * Gets the context this Article is executed in
1686 * @return IContextSource
1689 public function getContext() {
1690 if ( $this->mContext
instanceof IContextSource
) {
1691 return $this->mContext
;
1693 wfDebug( __METHOD__
. " called and \$mContext is null. Return RequestContext::getMain(); for sanity\n" );
1694 return RequestContext
::getMain();
1699 * Info about this page
1700 * @deprecated since 1.19
1702 public function info() {
1703 wfDeprecated( __METHOD__
, '1.19' );
1704 Action
::factory( 'info', $this )->show();
1708 * Mark this particular edit/page as patrolled
1709 * @deprecated since 1.18
1711 public function markpatrolled() {
1712 wfDeprecated( __METHOD__
, '1.18' );
1713 Action
::factory( 'markpatrolled', $this )->show();
1717 * Handle action=purge
1718 * @deprecated since 1.19
1720 public function purge() {
1721 return Action
::factory( 'purge', $this )->show();
1725 * Handle action=revert
1726 * @deprecated since 1.19
1728 public function revert() {
1729 wfDeprecated( __METHOD__
, '1.19' );
1730 Action
::factory( 'revert', $this )->show();
1734 * Handle action=rollback
1735 * @deprecated since 1.19
1737 public function rollback() {
1738 wfDeprecated( __METHOD__
, '1.19' );
1739 Action
::factory( 'rollback', $this )->show();
1743 * User-interface handler for the "watch" action.
1744 * Requires Request to pass a token as of 1.18.
1745 * @deprecated since 1.18
1747 public function watch() {
1748 wfDeprecated( __METHOD__
, '1.18' );
1749 Action
::factory( 'watch', $this )->show();
1753 * Add this page to the current user's watchlist
1755 * This is safe to be called multiple times
1757 * @return bool true on successful watch operation
1758 * @deprecated since 1.18
1760 public function doWatch() {
1761 wfDeprecated( __METHOD__
, '1.18' );
1762 return WatchAction
::doWatch( $this->getTitle(), $this->getContext()->getUser() );
1766 * User interface handler for the "unwatch" action.
1767 * Requires Request to pass a token as of 1.18.
1768 * @deprecated since 1.18
1770 public function unwatch() {
1771 wfDeprecated( __METHOD__
, '1.18' );
1772 Action
::factory( 'unwatch', $this )->show();
1776 * Stop watching a page
1777 * @return bool true on successful unwatch
1778 * @deprecated since 1.18
1780 public function doUnwatch() {
1781 wfDeprecated( __METHOD__
, '1.18' );
1782 return WatchAction
::doUnwatch( $this->getTitle(), $this->getContext()->getUser() );
1786 * Output a redirect back to the article.
1787 * This is typically used after an edit.
1789 * @deprecated in 1.18; call OutputPage::redirect() directly
1790 * @param $noRedir Boolean: add redirect=no
1791 * @param $sectionAnchor String: section to redirect to, including "#"
1792 * @param $extraQuery String: extra query params
1794 public function doRedirect( $noRedir = false, $sectionAnchor = '', $extraQuery = '' ) {
1795 wfDeprecated( __METHOD__
, '1.18' );
1797 $query = 'redirect=no';
1799 $query .= "&$extraQuery";
1801 $query = $extraQuery;
1804 $this->getContext()->getOutput()->redirect( $this->getTitle()->getFullURL( $query ) . $sectionAnchor );
1808 * Use PHP's magic __get handler to handle accessing of
1809 * raw WikiPage fields for backwards compatibility.
1811 * @param $fname String Field name
1813 public function __get( $fname ) {
1814 if ( property_exists( $this->mPage
, $fname ) ) {
1815 #wfWarn( "Access to raw $fname field " . __CLASS__ );
1816 return $this->mPage
->$fname;
1818 trigger_error( 'Inaccessible property via __get(): ' . $fname, E_USER_NOTICE
);
1822 * Use PHP's magic __set handler to handle setting of
1823 * raw WikiPage fields for backwards compatibility.
1825 * @param $fname String Field name
1826 * @param $fvalue mixed New value
1828 public function __set( $fname, $fvalue ) {
1829 if ( property_exists( $this->mPage
, $fname ) ) {
1830 #wfWarn( "Access to raw $fname field of " . __CLASS__ );
1831 $this->mPage
->$fname = $fvalue;
1832 // Note: extensions may want to toss on new fields
1833 } elseif ( !in_array( $fname, array( 'mContext', 'mPage' ) ) ) {
1834 $this->mPage
->$fname = $fvalue;
1836 trigger_error( 'Inaccessible property via __set(): ' . $fname, E_USER_NOTICE
);
1841 * Use PHP's magic __call handler to transform instance calls to
1842 * WikiPage functions for backwards compatibility.
1844 * @param $fname String Name of called method
1845 * @param $args Array Arguments to the method
1848 public function __call( $fname, $args ) {
1849 if ( is_callable( array( $this->mPage
, $fname ) ) ) {
1850 #wfWarn( "Call to " . __CLASS__ . "::$fname; please use WikiPage instead" );
1851 return call_user_func_array( array( $this->mPage
, $fname ), $args );
1853 trigger_error( 'Inaccessible function via __call(): ' . $fname, E_USER_ERROR
);
1856 // ****** B/C functions to work-around PHP silliness with __call and references ****** //
1859 * @param $limit array
1860 * @param $expiry array
1861 * @param $cascade bool
1862 * @param $reason string
1866 public function doUpdateRestrictions( array $limit, array $expiry, &$cascade, $reason, User
$user ) {
1867 return $this->mPage
->doUpdateRestrictions( $limit, $expiry, $cascade, $reason, $user );
1871 * @param $limit array
1872 * @param $reason string
1873 * @param $cascade int
1874 * @param $expiry array
1877 public function updateRestrictions( $limit = array(), $reason = '', &$cascade = 0, $expiry = array() ) {
1878 return $this->mPage
->updateRestrictions( $limit, $reason, $cascade, $expiry );
1882 * @param $reason string
1883 * @param $suppress bool
1885 * @param $commit bool
1886 * @param $error string
1889 public function doDeleteArticle( $reason, $suppress = false, $id = 0, $commit = true, &$error = '' ) {
1890 return $this->mPage
->doDeleteArticle( $reason, $suppress, $id, $commit, $error );
1898 * @param $resultDetails
1902 public function doRollback( $fromP, $summary, $token, $bot, &$resultDetails, User
$user = null ) {
1903 $user = is_null( $user ) ?
$this->getContext()->getUser() : $user;
1904 return $this->mPage
->doRollback( $fromP, $summary, $token, $bot, $resultDetails, $user );
1911 * @param $resultDetails
1912 * @param $guser User
1915 public function commitRollback( $fromP, $summary, $bot, &$resultDetails, User
$guser = null ) {
1916 $guser = is_null( $guser ) ?
$this->getContext()->getUser() : $guser;
1917 return $this->mPage
->commitRollback( $fromP, $summary, $bot, $resultDetails, $guser );
1921 * @param $hasHistory bool
1924 public function generateReason( &$hasHistory ) {
1925 $title = $this->mPage
->getTitle();
1926 $handler = ContentHandler
::getForTitle( $title );
1927 return $handler->getAutoDeleteReason( $title, $hasHistory );
1930 // ****** B/C functions for static methods ( __callStatic is PHP>=5.3 ) ****** //
1935 public static function selectFields() {
1936 return WikiPage
::selectFields();
1940 * @param $title Title
1942 public static function onArticleCreate( $title ) {
1943 WikiPage
::onArticleCreate( $title );
1947 * @param $title Title
1949 public static function onArticleDelete( $title ) {
1950 WikiPage
::onArticleDelete( $title );
1954 * @param $title Title
1956 public static function onArticleEdit( $title ) {
1957 WikiPage
::onArticleEdit( $title );
1965 * @deprecated since 1.WD, use ContentHandler::getAutosummary() instead
1967 public static function getAutosummary( $oldtext, $newtext, $flags ) {
1968 return WikiPage
::getAutosummary( $oldtext, $newtext, $flags );